#include <stdio.h>
#include <stdlib.h>
#include "lwip/apps/httpd.h"
#include "lwip/apps/httpd_opts.h"
#include "lwip/def.h"
#include "lwip/apps/fs.h"
#include <string.h>
#include "httpd_ssi.h"

#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))

const char *httpd_tags[] = {
    "Time",
};

uint16_t http_SSIHandler(
#if LWIP_HTTPD_SSI_RAW
                             const char* ssi_tag_name,
#else /* LWIP_HTTPD_SSI_RAW */
                             int iIndex,
#endif /* LWIP_HTTPD_SSI_RAW */
                             char *pcInsert, int iInsertLen
#if LWIP_HTTPD_SSI_MULTIPART
                             , uint16_t current_tag_part, uint16_t *next_tag_part
#endif /* LWIP_HTTPD_SSI_MULTIPART */
#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
                             , void *connection_state
#endif /* LWIP_HTTPD_FILE_STATE */
                             )
{
	return sprintf(pcInsert, "%s %s", __DATE__, __TIME__);
}

void httpd_ssi_init(void)
{
    http_set_ssi_handler(http_SSIHandler, httpd_tags, ARRAY_SIZE(httpd_tags));
}
